package com.ruoyi.im.enums;

import com.ruoyi.common.enums.BaseInteger;
import com.ruoyi.common.exception.ServiceException;
import lombok.Getter;

import java.util.Arrays;


@Getter
public enum ImMessageTypeEnum implements BaseInteger {
    TEXT(1,"文字"),
    IMAGE(2,"图片"),
    FILE(3,"文件"),
    VOICE(4,"语音"),
    VIDEO(5,"视频"),
    LOCATION(6,"位置"),
    LINK(7,"链接"),
    SYSTEM_MESSAGE(8,"系统消息"),
    EMOJI(9,"表情");

    private final Integer code;
    private final String desc;
    ImMessageTypeEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // 可选：每个枚举类可以定义自己的fromCode方法
    public static ImMessageTypeEnum fromCode(Integer code) {
        return BaseInteger.fromCode(ImMessageTypeEnum.class, code);
    }

    @Override
    public ImMessageTypeEnum valOf(Integer code) {
        return Arrays.stream(ImMessageTypeEnum.values()).filter(item -> item.code.equals(code)).findFirst().orElseThrow(() -> new ServiceException("枚举转换异常"));
    }
}

